package com.shareit.ocr.domain;
import java.io.FileNotFoundException;
import java.io.FileReader;

import javax.script.Invocable;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;

/**
 * 类说明
 * 
 * @author geai
 * @date 2018年1月24日 新建
 */
public class JavaScriptEval {

	public static final String scriptPath = System.getProperty("user.dir")
			+ "\\src\\main\\resources\\index2.js";
	public Invocable invocable;

	public JavaScriptEval() throws FileNotFoundException, ScriptException {

		ScriptEngineManager manager = new ScriptEngineManager();
	    ScriptEngine engine = manager.getEngineByName("js");
	    engine.eval(new FileReader(scriptPath));
	    invocable = (Invocable)engine;
		 
	}

	public String invokeFunction(String name,Object... args) {
		
		try {
			return (String)invocable.invokeFunction(name, args);
		} catch (Exception e) {
			return "";
		}
	}

}
